package utils

import (
	"boy-go/modules/generator/constants"
	"boy-go/modules/generator/model"
	"boy-go/pkg/xstr"
	"fmt"
	"regexp"
	"strings"
	"unicode"
)

// 校验数组是否包含指定值
func arraysContains(arr []string, targetValue string) bool {
	for _, value := range arr {
		if value == targetValue {
			return true
		}
	}
	return false
}

// 判断字符串是否以指定字符串结尾
func endsWithIgnoreCase(str string, suffix string) bool {
	return strings.HasSuffix(str, suffix)
}

// 将第一个字符转为大写
func toUpperFirst(s string) string {
	if len(s) < 1 {
		return ""
	}
	r := []rune(s)
	r[0] = unicode.ToUpper(r[0])
	return string(r)
}

// 将第一个字符转为小写
func toLowerFirst(s string) string {
	if len(s) < 1 {
		return ""
	}
	r := []rune(s)
	r[0] = unicode.ToLower(r[0])
	return string(r)
}
func permissionPrefix(moduleName string, businessName string) string {
	permissionPrefixStr := fmt.Sprintf("%s:%s", moduleName, businessName)
	return permissionPrefixStr
}

// 根据列类型获取字典组
func getDicts(genTable model.GenTable, genTableColumns []*model.GenTableColumn) string {
	dicts := make([]string, 0)
	addDicts(&dicts, genTableColumns)
	if genTable.SubTableName != nil {
		//子表
	}
	return strings.Join(dicts, ",")
}
func addDicts(dicts *[]string, columns []*model.GenTableColumn) {
	for _, column := range columns {
		if column.IsSuperColumn() == false && xstr.IsNotEmpty(&column.DictType) && xstr.EqualsAny(column.HtmlType, constants.HTML_SELECT, constants.HTML_RADIO, constants.HTML_CHECKBOX) {
			*dicts = append(*dicts, "'"+column.DictType+"'")
		}
	}
}

// 关键字替换
func replaceText(text *string) *string {
	if text == nil {
		return nil
	}
	// 编译一个不区分大小写的正则表达式
	pattern := regexp.MustCompile(`(?:表|boy-go)`)
	// 使用 ReplaceAllString 进行替换
	replaced := pattern.ReplaceAllString(*text, "hi")
	return &replaced
}
